 function getUrlRequest(){
            var url = decodeURI(location.search); //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                if (str.indexOf("&") != -1) {
                    strs = str.split("&");
                    for (var i = 0; i < strs.length; i++) {
                        theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                    }
                } else {
                    var key = str.substring(0,str.indexOf("="));
                    var value = str.substr(str.indexOf("=")+1);
                    theRequest[key] = decodeURI(value);
                }
            }
            return theRequest;
          }

          var Request = new Object();
          Request = getUrlRequest();
          var bid = decodeURI(Request["pd_type"]);
          function getRequest(){
            return Request;
          };
          $(function(){
            if(bid){
              console.log(bid); 
            }
            if(bid=='undefined'){
              console.log(bid);
            }
                      
            $('#selectf').form('load',{
                pd_type:Request['pd_type'],
                test_type:Request['test_type'],
                test_grade:Request['test_grade'],
                venture:Request['venture'],
                area:Request['area'],
            });
           
            // $('pd_type').combobox('setValue',bid);
            // $('test_type').combobox('setText','');            
            // $('test_grade').combobox('setText','');
            // $('venture').combobox('setText','');
            // $('area').combobox('setText','');
          });

        function getUserName(){
          return realname;
        }
        function getUserNo(){
          return userno;
        }
            var datagrid;
            var rowEditor=undefined;
            var editRow=undefined;
            var rq = getRequest();
            var surl = '';
            console.log("pd_type:"+rq['pd_type']);
            surl = "../../api/searchTestBOMByCondition?pd_type="+rq['pd_type']+"&test_type="+rq['test_type']+"&test_grade="+rq['test_grade']+"&venture="+rq['venture']+"&area="+rq['area'];

            function getSurl(){
              return surl;
            }

            console.log(surl);
            $(function(){
                datagrid=$("#showDataDg").datagrid({
                    url:surl,//加载的URL
                    method:"get",
                    isField:"id",
                    loadMsg:'数据加载中,请稍后...',
                    rownumbers: true, //是否加行号
                    singleSelect:true,
                    pagination:true,//显示分页
                    pageSize:20,//分页大小
                    pageList:[10,20,30,40],//每页的个数
                    beforePageText: '第',//页数文本框前显示的汉字 
                    afterPageText: '页    共 {pages} 页', 
                    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录', 
                    //fit:true,//自动补全
                    striped:true,
                    width:1200,
                    height:500,
                    fitColumns:true,
                    title:"测试BOM显示",
                    columns:[[      //每个列具体内容
                        {field:'ck',checkbox:true}, 
                        {field:'id',title:'测试BOMID',width:100,//hidden:true
                        }, 
                        {field:'productType',title:'产品类别',width:100,}, 
                        {field:'testType',title:'检测类型',width:100,}, 
                        {field:'productGrade',title:'试品等级',width:100,},                 
                        {field:'venture',title:'经营体',width:100,}, 
                        {field:'area',title:'销售区域',width:100,}, 
                        {field:'stdName',title:'测试标准名称',width:200,},
                        {field:'stdCode',title:'测试标准ID',width:100,hidden:true},
                        {field:'stdItermName',title:'测试项目名称',width:150,},
                        {field:'stdItermCode',title:'测试项目ID',width:100,hidden:true},
                        {field:'stdSubitermName',title:'工况',width:100,},                          
                        {field:'stdSubitermCode',title:'测试子项ID',width:100,hidden:true},
                        {field:'addUser',title:'添加人工号',width:100,},
                        {field:'addUserName',title:'添加人',width:100,},
                        {field:'addTime',title:'添加时间',width:100,},
                        {field:'orderArry',title:'默认顺序',width:100,},
                        {field:'mark',title:'标志',width:100,hidden:true},
                    ]],
                    toolbar:[              //工具条
                           
                      {text:"删除",iconCls:"icon-ktsyDelete",handler:function(){
                          var rows=datagrid.datagrid('getSelections');
                
                          if(rows.length<=0)
                          {
                              $.messager.alert('警告','您没有选择','error');
                          }else
                          {
                              $.messager.confirm('确定','您确定要删除吗',function(t){
                                  if(t)
                                  {                                    
                                      $.ajax({
                                          url : '../../api/deleteTestBOM',
                                          data : rows[0],
                                          dataType : 'json',
                                          success : function(r) {
                                              if (r==1) {
                                                  datagrid.datagrid('acceptChanges');
                                                  $.messager.show({
                                                      msg : r.msg,
                                                      title : '成功'
                                                  });
                                                  editRow = undefined;
                                                  datagrid.datagrid('reload');

                                                  //操作记录
                                                  saveSystemLog("测试BOM管理","www.ktsy.com/menu_nj/TestStandardManage/TestBOMEdit","4","删除测试BOM",realname,userno);
                                              } else {
                                                  /*datagrid.datagrid('rejectChanges');*/
                                                  $.messager.alert('失败', '删除失败', 'error');
                                              }
                                              datagrid.datagrid('unselectAll');
                                          }
                                      });
                                  }
                              })
                          }
                      }},             
                    ],
                  });
              });

var datagrid1;
          var rowEditor=undefined;
          var editRow=undefined;

          $(function(){

              datagrid1=$("#selectDataDg").datagrid({
                  url:"",//加载的URL ../../api/getAllTestStandardUnion
                  method:"get",
                  idField:"subitem_id",
                  loadMsg:'数据加载中,请稍后...',
                  rownumbers: true, //是否加行号
                  singleSelect:true,
                  // pagination:true,//显示分页
                  pageSize:10,//分页大小
                  pageList:[10,20,30,40],//每页的个数
                  beforePageText: '第',//页数文本框前显示的汉字 
                  afterPageText: '页    共 {pages} 页', 
                  displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录', 
                  //fit:true,//自动补全
                  striped:true,
                  width:1200,
                  height:400,
                  fitColumns:true,
                  title:"测试BOM编辑",
                  columns:[[      //每个列具体内容
                      { field:'ck',checkbox:true}, 
                      {field:'template_id',title:'标准ID',width:100,hidden:true
                      }, 
                      {field:'template_name',title:'标准名称',width:100,}, 
                      {field:'item_id',title:'标准项ID',width:100,hidden:true
                      }, 
                      {field:'item_name',title:'标准项名称',width:100,},
                      {field:'subitem_id',title:'标准子项ID',width:100,hidden:true
                      },          
                      {field:'subitem_name',title:'工况',width:100,}
                  ]],
                  toolbar:[              //工具条
                      {text:"增加",iconCls:"icon-ktsyAdd",handler:function(){//添加测试BOM

                        var rows=datagrid1.datagrid('getSelections');//获取行数据

                        //获取选择框数据
                        var productType = $('#pd_type').combobox('getText');
                        var testType = $('#test_type').combobox('getText');
                        var productGrade = $('#test_grade').combobox('getText');
                        var venture = $('#venture').combobox('getText');
                        var area = $('#area').combobox('getText');
                        

                        // console.log(productGrade);
                        console.log(rows[0]);
                        if(productType =="" && testType =="" && productGrade =="" && venture =="" && area ==""){
                          $.messager.alert('错误','请选择“产品类别”、“检测类型”等信息', 'error');
                        }else{
                          var rurl = "../../menu_nj/TestStandardManage/TestBOMEdit?pd_type="+productType+"&test_type="+testType+"&test_grade="+productGrade+"&venture="+venture+"&area="+area;
                          $("#showDataDg").datagrid('load',rurl);
                          searchByConditions();
                          if(rows.length<=0){
                            $.messager.alert('警告','您没有选择','error');
                          }else{
                            var stdSubitermName = rows[0]['subitem_name'];
                            $.ajax({
                              url: '../../api/insertTestBOM',
                              type: 'GET',
                              dataType: 'json',
                              data: {productType:productType , testType:testType ,productGrade:productGrade , venture:venture , area:area , stdName:rows[0]['template_name'] , stdCode:rows[0]['template_id'] , stdItermName:rows[0]['item_name'] , stdItermCode:rows[0]['item_id'] , stdSubitermName:stdSubitermName , stdSubitermCode:rows[0]['subitem_id'] , orderArry:1 , addUser:getUserNo() , addUserName:getUserName()},                            
                              success : function(r) {
                                
                                if (r==1) {
                                    // datagrid.datagrid('acceptChanges');
                                    $.messager.show({
                                        msg : r.msg,
                                        title : '成功'
                                    });
                                    // editRow = undefined;
                                    // $('#showDataDg').datagrid('reload');
                                    // $('#showDataDg').datagrid('load',getSurl());
                                    searchByConditions();

                                    //操作记录
                                    saveSystemLog("测试BOM管理","www.ktsy.com/menu_nj/TestStandardManage/TestBOMEdit","3","增加测试BOM",realname,userno);
                                } else if(r==7){
                                    $.messager.alert('警告','测试子项添加重复！',"error");
                                     datagrid1.datagrid('beginEdit', editRow);
                                }else  {
                                    /*datagrid.datagrid('rejectChanges');*/
                                    datagrid1.datagrid('beginEdit', editRow);
                                    $.messager.alert('警告', r.msg, 'error');
                                }
                              }
                            });
                          }
                        }
                      }
                    }
                  ],
              });
          });


          function searchTsuByCondition (){
            var template_name = $('#template_name').textbox('getValue');
            var item_name = $('#item_name').textbox('getValue');
            var searchTsuUrl = '';

            console.log('template_name:'+template_name);
            console.log('item_name:'+item_name);

            searchTsuUrl='../../api/getAllTestStandardUnionByNames?template_name='+template_name+'&item_name='+item_name;

            $('#selectDataDg').datagrid('reload',searchTsuUrl);

            

          }

          function searchByConditions(){
            var pd_type = $("#pd_type").combobox("getText");
            var test_type = $("#test_type").combobox("getText");
            var test_grade = $("#test_grade").combobox("getText");
            var venture = $("#venture").combobox("getText");
            var area = $("#area").combobox("getText");
            var url = "../../api/searchTestBOMByCondition?pd_type="+pd_type+"&test_type="+test_type+"&test_grade="+test_grade+"&venture="+venture+"&area="+area;

            $("#showDataDg").datagrid("reload",url);
          }

          //记录用户登录系统日志
          function saveSystemLog(pagetitle,page,operation,detail,userrealname,userno){
            // alert("保存日志信息");
            $.ajax({
              type:"get",
              dataType : "json",
              url:"../../api/insertSystemLog",
              data:{pagetitle:pagetitle,page:page,operation:operation,detail:detail,userrealname:userrealname,userno:userno},
              success:function(r){
                  if (r==1){
                    console.log("保存"+r+"条日志信息");
                  }
              }
            });
          }